<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/11 0011
 * Time: 0:09
 */
namespace Admin\Controller;

use Think\Controller;
class ConfigController extends CommonController {
    /***
     * 修改密码
     */
    public function index()
    {
        if(IS_POST)
        {
            /***
             * 判断原始密码是否正确
             */
            $old_password = set_password(I('post.old_password'));
            if($old_password != $_SESSION['user']['password']) {
                $this->error("原始密码输入错误");
            }
            /***
             * 判断输入新密码是否一致
             */
            $password = set_password(I("post.password"));
            $check_password = set_password(I('post.check_password'));
            if($check_password != $password) {
                $this->error("密码不一致");
            }
            /***
             * 给新密码加密 并且修改数据库
             */
                $User = M('User');
                $user_id = $_SESSION['user']['id'];
                $password = set_password(I('post.password'));
                $User-> where("id='$user_id'")->setField('password',$password);
                $this->success("恭喜你，密码修改成功",U('User/login'));
        }else{
            $this->display();
        }
    }
    public function site_info()
    {
        $site = $this->site->find();
        $this->assign('site',$site);
        $this->display();
    }
    public function clear_cache()
    {
        rm_dir(RUNTIME_PATH);
        $this->success('清除缓存成功', U('Index/index'));
    }
    public function about_info(){
        $about = $this->about->find();
        $this->assign('about',$about);
        $this->display();
    }

}